package cn.waqwb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        try {
            //1、加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2、创建连接
            Connection connection =
                    DriverManager.getConnection("jdbc:mysql://localhost:3306/dang",
                            "waqwb","qiu55555");
            //3、创建语句对象
            String sql = "select * from t_user";
            //4、执行sql语句
            Statement statement = connection.createStatement();
            //5、处理结果集
            ResultSet resultSet = statement.executeQuery(sql);
            /*
             * 遍历结果集，resultSet.next()遍历，
             * 如果下一个结果不存在，条件为false，跳出循环
             */
            while (resultSet.next()){
                System.out.println(resultSet.getString("email"));
            }
            //6、关闭连接
            connection.close();

        } catch (Exception e){
            e.printStackTrace();
        }


    }
}
